package com.tps.controller;

import com.tps.feign.GoodsFeign;
import com.tps.service.OrderService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author charlee
 * @date 2018/4/30
 */
@Api(description = "订单相关接口")
@RestController
public class OrderController {

    private final GoodsFeign goodsFeign;

    private final OrderService orderService;

    public OrderController(GoodsFeign goodsFeign, OrderService orderService) {
        this.goodsFeign = goodsFeign;
        this.orderService = orderService;
    }

    @ApiOperation(value = "说话", notes = "使用Feign调用goods-server的hello方法，返回一段话")
    @GetMapping("/say/{username}")
    @PreAuthorize("hasAuthority('read')")
    public String hello(@ApiParam(value = "用户名", name = "username", required = true) @PathVariable String username) {
        return goodsFeign.sayHello(username);
    }

    @ApiOperation("测试事务回滚")
    @GetMapping("/save")
    @PreAuthorize("hasAuthority('write')")
    public void save(@ApiParam(value = "是否回滚 true是 false否") @RequestParam Boolean isRollBack) {
        orderService.save(isRollBack);
    }

}
